<?php
/**
 * Created by PhpStorm.
 * User: daojia
 * Date: 2020/5/8
 * Time: 16:57
 */

namespace app\store\controller\shop;

use app\common\service\order\Refund as RefundService;
use app\store\controller\Controller;

use app\store\model\store\shop\Payorder as OrderModel;
class Payorder extends Controller
{
    public function index(){
        $OrderModel = new OrderModel();
        $list = $OrderModel->getList();
        return $this->fetch('index', compact('list'));
    }
    public function refund($money, $order_id){
        $info = db('pay_order')->where('order_id',$order_id)->find();
        if($money > $info['pay_price']){
            return $this->renderError('您输入的退款金额不能大于付款金额');
        }
        // 执行原路退款
        $order['wxapp_id'] = $info['wxapp_id'];
        $order['transaction_id'] = $info['transaction_id'];
        $order['pay_price'] = $info['pay_price'];
        $order['pay_type']['value'] = 20;
        (new RefundService)->execute($order, $money);
        //获取扣除积分
        $points = integralJiSuan($money);
        db('pay_order')->where('order_id',$order_id)->setDec('pay_price',$money);
        db('pay_order')->where('order_id',$order_id)->setDec('gift_money',$points);
        db('user')->where('user_id',$info['user_id'])->setDec('points',$points);
        return $this->renderSuccess('退款成功');
    }
}